﻿//TODO: test

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;

namespace LowLevelGraphics.Filter
{
    /// <summary>
    /// If we use an Exponent in the intervall [0..1]
    /// we can use this to calculate a radical
    /// </summary>
    public class Radical : Exponential
    {
        protected float m_fRootExponent = 0.0f;
        
        /// <summary>
        /// Initializes a new instance of the <see cref="Radical"/> class.
        /// </summary>
        public Radical()
            : base()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Radical"/> class.
        /// </summary>
        /// <param name="_fRootExponent">The _f root exponent.</param>
        /// <param name="_fScaleVal">The _f scale val.</param>
        /// <param name="_fOffset">The _f offset.</param>
        /// <param name="_bConvertToGrayScale">if set to <c>true</c> [_b convert to gray scale].</param>
        public Radical(float _fRootExponent, float _fScaleVal, float _fOffset, bool _bConvertToGrayScale)
        {
            m_fExponent = 1 / _fRootExponent;
            m_fScale = _fScaleVal;
            m_fOffset = _fOffset;
            m_bConvertToGrayscale = _bConvertToGrayScale;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Radical"/> class.
        /// </summary>
        /// <param name="_bConvertToGrayScale">if set to <c>true</c> [_b convert to gray scale].</param>
        public Radical(bool _bConvertToGrayScale)
            : base(_bConvertToGrayScale)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Radical"/> class.
        /// </summary>
        /// <param name="_radical">The _radical.</param>
        internal Radical(Radical _radical)
        {
            this.m_fRootExponent = _radical.m_fRootExponent;
            this.m_bConvertToGrayscale = _radical.m_bConvertToGrayscale;
        }

        /// <summary>
        /// Execute this Filter
        /// A Debug Statement is written if a concrete Filter is called
        /// </summary>
        /// <param name="_bitmap"></param>
        /// <returns></returns>
        public override UnsafeBitmap Execute(UnsafeBitmap _bitmap)
        {
            this.m_fExponent = 1 / m_fRootExponent;
            return base.Execute(_bitmap);
        }

        /// <summary>
        /// This is used to clone a filter, each filter must implement it's own clone functionality
        /// </summary>
        /// <returns></returns>
        public override object Clone()
        {
            return new Radical(this);
        }
    }
}
